package org.example.service.impl;


import org.example.mapper.ClazzMapper;
import org.example.mapper.EmpMapper;
import org.example.mapper.StudentMapper;
import org.example.pojo.ClassOption;
import org.example.pojo.JobOption;
import org.example.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ClazzMapper clazzMapper;
    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;
    @Override
    public JobOption getEmpJobData() {
        List<Map<String, Object>> list = empMapper.countEmpJobData();
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(jobList,dataList);
    }

    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public ClassOption getClassData() {
        List<Map> classData = clazzMapper.countClassData();
        List<Object> classNames = classData.stream().map(dataMap -> dataMap.get("name")).toList();
        List<Object> studentCounts = classData.stream().map(dataMap -> dataMap.get("student_count")).toList();
        return new ClassOption(classNames, studentCounts);
    }

    @Override
    public List<Map> getStudentDegreeData() {
        List<Map> originalData = studentMapper.countStudentDegree();
        return originalData.stream()
                .map(map -> {
                    Map<String, Object> newMap = new java.util.HashMap<>();
                    newMap.put("name", map.get("degree_name"));
                    newMap.put("value", map.get("count"));
                    return newMap;
                })
                .collect(java.util.stream.Collectors.toList());
    }

}
